﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Laba1
{
   public class PrincipleOfRatingByDate 
   {
        private List<RatingByDate> _ratingByDates;

       public PrincipleOfRatingByDate(List<RatingByDate> ratingByDates)
       {
           _ratingByDates = ratingByDates;
       }

       public int GetRating(DateTime date, PracticalTask task)
       {
            _ratingByDates.OrderBy(ratingByDate => ratingByDate.Delay);
           int delay = date.Subtract(task.Deadline).Days;
/*           foreach (var ratingByDate in _ratingByDates)
           {
               if (delay < ratingByDate.Delay) return ratingByDate.Rating;
           }
           return 0;*/
           return _ratingByDates.OrderBy(ratingByDate => ratingByDate.Delay)
               .Where(ratingByDate => ratingByDate.Delay <= delay).FirstOrDefault().Rating;
       }
   }
}
